<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var deleteNode = function (head, val) {
      if (head.val == val) {
        return head.next
      }
      /**
       * 假设【1，2，3】，目标值是2
       * 当前head是1.
       * 本来head.next是2,但是调用deletenode函数的时候刚刚好2==2,把2（head）的下一个值3的指针返回回去
       * 所以head.next = 3
       * 1->3
       * 
      */
      head.next = deleteNode(head.next, val);
      return head
    };
    console.log(deleteNode(head = [4, 5, 1, 9], val = 5))
  </script>
</body>

</html>